<template>
  <nut-config-provider :theme="theme" :theme-vars="themeVars">
    <view :style="{backgroundColor: themeVars.pageBackgroundColor,padding: themeVars.pagePadding,height:'100vh'}">
      <!--      顶部-->
      <view class="user-top">
        <view class="user-top-left" v-if="token" @click="Taro.navigateTo({url:'/pages/view/editUserInfo/index'})">
          <nut-avatar size="large">
            <img
                :src="userInfo.avatar"/>
          </nut-avatar>
          <view style="width: 120px;margin-left: 10px" class="single-line-text">{{ userInfo.nickname }}</view>
        </view>

        <view class="user-top-left" v-else @click="Taro.navigateTo({url:'/pages/view/login/index'})">
          <nut-avatar size="large">
            <img
                src="https://sdztl.oss-cn-hangzhou.aliyuncs.com/tuowulian-offline/images/user/defaultAvatar.png"/>
          </nut-avatar>
          <view style="width: 120px;margin-left: 10px" class="single-line-text">点击登录</view>
        </view>


        <view>

        </view>
      </view>
      <!--数据-->
      <view class="card" style="display: flex;justify-content: space-around;margin-top: 10px">
        <UserNum text="我的关注" :number="userDataJson.followNum" @click="Taro.navigateTo({url:'/pages/view/myFollow/index'})"/>
        <UserNum text="我的收藏" :number="userDataJson.collectNum" @click="Taro.navigateTo({url:'/pages/view/myCollect/index'})"/>
        <UserNum text="我的足迹" :number="userDataJson.scanNum" @click="Taro.navigateTo({url:'/pages/view/myTrace/index'})"/>
      </view>
      <!--用户服务-->
      <view class="card" style="display: flex;flex-direction:column;;margin-top: 10px">
        <NavPanel title="客户服务">
          <UserNav name="我的发布" icon="https://sdztl.oss-cn-hangzhou.aliyuncs.com/tuowulian-offline/images/user/%E6%88%91%E7%9A%84%E5%8F%91%E5%B8%83.png"
                   @click="Taro.navigateTo({url:'/pages/view/myPublish/index'})"/>
          <UserNav name="我要入驻" icon="https://sdztl.oss-cn-hangzhou.aliyuncs.com/tuowulian-offline/images/user/%E6%88%91%E8%A6%81%E5%85%A5%E9%A9%BB.png"
                   @click="Taro.navigateTo({url:'/pages/view/settleForm/index'})"/>
          <UserNav name="联系客服" icon="https://sdztl.oss-cn-hangzhou.aliyuncs.com/tuowulian-offline/images/user/%E8%81%94%E7%B3%BB%E5%AE%A2%E6%9C%8D.png"/>
        </NavPanel>
        <NavPanel title="厂家服务">
          <UserNav name="产品管理" icon="https://sdztl.oss-cn-hangzhou.aliyuncs.com/tuowulian-offline/images/user/%E4%BA%A7%E5%93%81%E7%AE%A1%E7%90%86.png"
                   @click="Taro.navigateTo({url:'/pages/view/commodityManage/index',complete: toProductList})"/>
          <UserNav name="企业信息" icon="https://sdztl.oss-cn-hangzhou.aliyuncs.com/tuowulian-offline/images/user/%E4%BC%81%E4%B8%9A%E4%BF%A1%E6%81%AF.png"
                   @click="Taro.navigateTo({url:'/pages/view/enterpriseForm/index'})"/>
        </NavPanel>
        <NavPanel title="我要推广">
          <UserNav name="推广" icon="https://sdztl.oss-cn-hangzhou.aliyuncs.com/tuowulian-offline/images/user/%E6%8E%A8%E5%B9%BF.png" @click="Taro.navigateTo({url:'/pages/view/promotion/index'})"/>
        </NavPanel>
      </view>


    </view>

  </nut-config-provider>
</template>

<script setup>
import {ref} from 'vue';
import useTheme from "../../../hooks/useTheme";
import UserNum from "../../../components/userNum/index.vue";
import UserNav from "../../../components/userNav/index.vue";
import NavPanel from "../../../components/navPanel/index.vue";
import Taro from "@tarojs/taro";
import {useDidShow} from '@tarojs/taro'
import {twEnterpriseMyDetail} from "../../../api/enterprise";
import {twEnterpriseSettleMySettle} from "../../../api/enterpriseSettle";
import {  userData} from "../../../api/login";

const {theme, themeVars} = useTheme()


const token = ref("")
const userInfo = ref({})

useDidShow(() => {
  // const token = mainStore.token
  console.log("process.env.NODE_ENV", process.env.NODE_ENV)
  // console.log("token ", token.value)
  token.value = Taro.getStorageSync('token')
  const userInfoStr = Taro.getStorageSync('userInfo');
  if (userInfoStr) {
    userInfo.value = JSON.parse(userInfoStr)
  }
  getUserData()

})


const toProductList = (res) => {
  twEnterpriseSettleMySettle().then(res => {
    console.log("twEnterpriseMyDetail", res)
    if (200 == res.code) {
      if (res.data) {
        if (res.data.auditStatus === 'SUCCESS') {
          return
        }else{
          Taro.redirectTo({url:'/pages/view/settleForm/index'})
        }
      } else {
        Taro.redirectTo({url:'/pages/view/settleForm/index'})
      }
    }
  })
}

const userDataJson = ref({
  followNum:0,
  collectNum:0,
  scanNum:0,
})
const getUserData = () => {

  const token = Taro.getStorageSync('token')
  if (token) {
    userData().then(res=>{
      if (200 == res.code) {
        userDataJson.value = res.data
      }
    })
  }

}




</script>

<style>

.user-top {

}

.user-top-left {
  display: flex;
  align-items: center;
  font-size: 30px;
}


</style>